﻿/**
 * 
 * @file   FITKVAOneHDF5IOInterface.h
 * @brief  VAOneHDF5的读写组件接口
 * @author TanDongYang (tandongyang@diso.cn)
 * @date   2024-11-22
 * 
 */

#ifndef FITKVAONEHDF5IOINTERFACE_H
#define FITKVAONEHDF5IOINTERFACE_H

#include <QObject>
#include "FITKVAOneHDF5IOAPI.h"
#include "FITK_Kernel/FITKAppFramework/FITKComponentInterface.h"
#include "FITK_Kernel/FITKCore/FITKAbstractObjectContainer.hpp"

namespace Interface
{
    class FITKAbstractIO;
}

namespace VAOne
{
    /**
     * @brief   VAOneHDF5的读写组件接口
     * @author  TanDongYang (tandongyang@diso.cn)
     * @date    2024-11-22 
     */
    class FITKVAOneHDF5IO_API FITKVAOneHDF5IOInterface : public QObject,
        public AppFrame::FITKComponentInterface
    {
        Q_OBJECT
    public:

        /**
         * @brief   Construct a new FITKVAOneHDF5IOInterface object
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        explicit FITKVAOneHDF5IOInterface() = default;

        /**
         * @brief   Destroy the FITKVAOneHDF5IOInterface object
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        virtual ~FITKVAOneHDF5IOInterface() = default;

        /**
         * @brief   执行操作
         * @param[i]   indexPort    1-读取 2-写出
         * @return  bool 执行是否成功，若多线程读写，返回值无实际意义
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        bool exec(const int indexPort) override;

        /**
         * @brief   设置文件名称
         * @param[i]   fileName      文件名称，要求包含绝对路径
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        void setFileName(const QString& fileName);

        /**
         * @brief       是否在独立线程执行读写
         * @param[i]   inThread       是否在独立线程执行读写操作
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        void runInThread(const bool & inThread = true);

        /**
         * @brief   是否正在执行
         * @return true
         * @return false
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        bool isRunning();

        /**
         * @brief   执行是否成功
         * @return true
         * @return false
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        bool isSuccess();

        /**
         * @brief   获取部件名称，不能重复  返回 VAOneHDF5IO
         * @return  QString
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        QString getComponentName() override;

    signals:

        /**
         * @brief   读写线程结束信号
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        void ioThreadFinishedSig();

    private:

        /**
         * @brief   文件名称
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        QString _fileName{};

        /**
         * @brief   是否在线程运行
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        bool _runInThread{ true };

        /**
         * @brief   是否执行成功标记
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        bool _success{ false };


        /**
         * @brief   io 对象
         * @author  TanDongYang (tandongyang@diso.cn)
         * @date    2024-11-22 
         */
        Core::FITKAbstractObjectContainer<Interface::FITKAbstractIO> _io{ nullptr };

    };



}

#endif // FITKVAONEHDF5IOINTERFACE_H
